package de.uni.muenster.idw2.autoverbal.data;

import java.util.ArrayList;

import de.uni.muenster.idw2.data.Edge;
import de.uni.muenster.idw2.data.Landmark;
import de.uni.muenster.idw2.data.Vertex;




public class Choreme {

  private Integer multiplicity;

  private int instruction;

  private Boolean isDChoreme;

  private Boolean isEChoreme;

  private ArrayList<Vertex> vertices;
  
  private ArrayList<Edge> edges;
  
	ArrayList<Landmark> landmarksLeft;
	ArrayList<Landmark> landmarksRight;

  public Choreme(){
	  this.multiplicity=0;
	  this.instruction=Pair.STRAIGHT;
	  this.isDChoreme=false;
	  this.isEChoreme=false;
	  this.vertices=new ArrayList<Vertex>();
	  this.edges=new ArrayList<Edge>();
  }
  
  public Landmark getBestLandmarkLeft(){
	  if (landmarksLeft.isEmpty()) return null;
	  if (landmarksLeft.size()==1) return landmarksLeft.get(0);
	  
	  int indexBest = 0;
	  for (int i=1; i<landmarksLeft.size()-1; i++){
		  if (landmarksLeft.get(i).getVisibility() > landmarksLeft.get(indexBest).getVisibility())
			  indexBest = i;
	  }
	  
	  return landmarksLeft.get(indexBest);
  }
  
  public Landmark getBestLandmarkRight(){
	  
	  if (landmarksRight.isEmpty()) return null;
	  if (landmarksRight.size()==1) return landmarksRight.get(0);
	  
	  int indexBest = 0;
	  for (int i=1; i<landmarksRight.size()-1; i++){
		  if (landmarksRight.get(i).getVisibility() > landmarksRight.get(indexBest).getVisibility())
			  indexBest = i;
	  }
	  
	  return landmarksRight.get(indexBest);
  }
  
  public Landmark getBestLandmark(){

	  if (getBestLandmarkLeft() == null && getBestLandmarkRight() == null) return null;
	  if (getBestLandmarkLeft() == null && getBestLandmarkRight() != null) return getBestLandmarkRight();
	  if (getBestLandmarkLeft() != null && getBestLandmarkRight() == null) return getBestLandmarkLeft();
	  if (getBestLandmarkLeft() != null && getBestLandmarkRight() != null) {
		  if (getBestLandmarkLeft().getVisibility()> getBestLandmarkRight().getVisibility()) return getBestLandmarkLeft();
		  else return getBestLandmarkRight();
	  }
	  
	  return null;
  }
  
  public String getVerbalDescription(){
	  if(getBestLandmark()==null) return "-";
	  
	  if (!landmarksLeft.isEmpty() && landmarksLeft.contains(getBestLandmark())) return "Pass " + getBestLandmarkLeft().getText() + " to your left";
	  else  return "Pass " + getBestLandmarkRight().getText() + " to your right";
  }
  
  public Integer getMultiplicity() {
	  return this.multiplicity;
  }

  public void setMultiplicity(Integer multiplicity) {
	  this.multiplicity=multiplicity.intValue();
  }

  public int getInstruction() {
	  return this.instruction;
  }

  public void setInstruction(int instruction) {
	  this.instruction=instruction;
  }

  public Boolean isDChoreme() {
	  return this.isDChoreme;
  }

  public void setIsDChoreme(Boolean isDChoreme) {
	  this.isDChoreme=isDChoreme;
  }

  public Boolean isEChoreme() {
	  return this.isEChoreme;
  }

  public void setIsEChoreme(Boolean isEChoreme) {
	  this.isEChoreme=isEChoreme;
  }

  public Vertex getVertex(Integer position) {
	  return this.vertices.get(position.intValue());
  }

  public void setVertex(Integer position, Vertex vertex) {
	  this.vertices.set(position.intValue(), vertex);
  }
  
  public void addVertex(Vertex vertex) {
	  this.vertices.add(vertex);
  }
  
  public Edge getEdge(Integer position){
	  return this.edges.get(position);
  }
  
  public void addEdge(Edge edge){
	  this.edges.add(edge);
  }

	public ArrayList<Landmark> getLandmarksLeft() {
		return landmarksLeft;
	}

	public void setLandmarksLeft(ArrayList<Landmark> landmarksLeft) {
		this.landmarksLeft = landmarksLeft;
	}

	public ArrayList<Landmark> getLandmarksRight() {
		return landmarksRight;
	}

	public void setLandmarksRight(ArrayList<Landmark> landmarksRight) {
		this.landmarksRight = landmarksRight;
	}

	public ArrayList<Vertex> getVertices() {
		return vertices;
	}

	public void setVertices(ArrayList<Vertex> vertices) {
		this.vertices = vertices;
	}

	public ArrayList<Edge> getEdges() {
		return edges;
	}

	public void setEdges(ArrayList<Edge> edges) {
		this.edges = edges;
	}
	
	
}